<template>
  <div class="app-container">
    <el-dialog :title="titles[flag]" :visible.sync="dialogVisible" width="50%">
      <el-form ref="form" :model="form" :disabled="flag==1" v-loading="loading">
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="快递名称" prop="expressName" required>
              <div v-if="flag==1">{{ form.expressName }}</div>
              <el-input v-else v-model="form.expressName" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="快递编码" prop="expressCode" required>
              <div v-if="flag==1">{{ form.expressCode }}</div>
              <el-input v-else v-model="form.expressCode" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="业务名称" prop="serviceName" required>
              <div v-if="flag==1">{{ form.serviceName }}</div>
              <el-input v-else v-model="form.serviceName" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="站点名称" prop="siteName" required>
              <div v-if="flag==1">{{ form.siteName }}</div>
              <el-input v-else v-model="form.siteName" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="站点编码" prop="siteCode" required>
              <div v-if="flag==1">{{ form.siteCode }}</div>
              <el-input v-else v-model="form.siteCode" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="面单模版" prop="tempId" required>
              <div v-if="flag==1">{{ form.tempId }}</div>
              <el-input v-else v-model="form.tempId" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="云打印机" prop="printerId" required>
              <div v-if="flag==1">{{ form.printerId }}</div>
              <el-input v-else v-model="form.printerId" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系人" prop="recipient" required>
              <div v-if="flag==1">{{ form.recipient }}</div>
              <el-input v-else v-model="form.recipient" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="recipientTel" required>
              <div v-if="flag==1">{{ form.recipientTel }}</div>
              <el-input v-else v-model="form.recipientTel" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible=false">取 消</el-button>
        <el-button type="primary" @click="dialogOk" v-if="flag!=1">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>


import {addExpressShop, updateExpressShop} from "../../../../api/expressMng";

export default {
  data() {
    return {
      flag: 0,
      titles: ['新增', '详情', '修改'],
      loading: false,
      dialogVisible: false,
      form: {}
    }
  },
  methods: {
    show(flag, form) {
      this.flag = flag
      this.dialogVisible = true
      this.resetForm('form')
      this.form = form
    },
    dialogOk() {
      this.$refs.form.validate(e => {
        if (e) {
          this.loading = true
          if (!this.flag) {
            addExpressShop(this.form).then(res => {
              this.dialogVisible = false
              this.$emit('ok')
              this.$message.success('新增成功')
            }).finally(e => {
              this.loading = false
            })
          } else {
            updateExpressShop(this.form).then(res => {
              this.dialogVisible = false
              this.$emit('ok')
              this.$message.success('修改成功')
            }).finally(e => {
              this.loading = false
            })
          }
        }
      })
    },
  }
}
</script>
